import '../helper/dioHelper2.dart';

class Things {
  int ID;
  String TName;
  String TType;
  String SStyle;
  String Unit;
  String Storage;
  String Remarks;

  Things(this.ID, this.TName, this.TType, this.SStyle, this.Unit, this.Storage,
      this.Remarks);
  Things.fromJson(Map<String, dynamic> json)
      : ID = json["ID"],
        TName = json["TName"],
        TType = json["TType"],
        SStyle = json["SStyle"],
        Unit = json["Unit"],
        Storage = json["Storage"],
        Remarks = json["Remarks"];
  Map<String, dynamic> toJson() => {
        'ID': ID,
        'TName': TName,
        'TType': TType,
        'SStyle': SStyle,
        'Unit': Unit,
        'Storage': Storage,
        'Remarks': Remarks,
      };

  static Future<bool> Add(Things x1) async {
    var response = await DioHelper.Post("/Things/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(Things x1) async {
    var response = await DioHelper.Post("/Things/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(Things x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/Things/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<Things?> Get(String where, dynamic data) async {
    var response = await DioHelper.Post("/Things/GetByWhere", {
      "Where": where,
      "obj": data,
    });

    if (response.statusCode == 200) return new Things.fromJson(response.data);
    return null;
  }

  static Future<List<Things>> GetList(
      String where, dynamic data, int pageIndex, int pageSize) async {
    var response = await DioHelper.Post("/Things/GetListByWhere", {
      "Where": where,
      "obj": data,
      "PageIndex": pageIndex,
      "PageSize": pageSize,
    });
    var list1 = <Things>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new Things.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<Things>> GetAllList() async {
    var response = await DioHelper.Get("/Things/GetAllList", {});
    var list1 = <Things>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new Things.fromJson(x));
      }
    }
    return list1;
  }
}
